package agency.sales;

import java.util.Date;

import agency.Sales;
import dict.TransactionDict;
import entities.TBank;
import entities.TBc;
import entities.TCard;
import entities.TTransaction;
import utils.DateUtil;
import utils.StringUtil;

public class Tstedc implements Sales {

	public void process(TBc bc, TTransaction transaction, TBank bank, TCard card) {
		int rand = (int) (Math.random() * 100);
		if (card.getCrdNumber().startsWith("4283")) {
			bc.setBcRef(StringUtil.number(24));
			bc.setBcCard(card.getCrdFake());
			bc.setBcTime(DateUtil.format(new Date(), DateUtil.DATE));
			bc.setBcMark("00");
			bc.setBcInfo("4283 payment ok");
			bc.setBcCode(TransactionDict.TRANSACTION_SUCCESS);
			bc.setBcMessage(TransactionDict.MESSAGES.get(TransactionDict.TRANSACTION_SUCCESS));
			bc.setBcState("1");
			return;
		}
		
		if (card.getCrdNumber().startsWith("4111")) {
			bc.setBcMark("99");
			bc.setBcInfo("payment fail");
			bc.setBcCode("AT01");
			bc.setBcMessage("Sorry ,test transaction failure");
			return;
		}

		if (rand % 3 == 0) {
			bc.setBcMark("99");
			bc.setBcInfo("test channel has 1/3 persent chance get failure result ");
			bc.setBcCode("AT02");
			bc.setBcMessage("Sorry , test transaction has 1/3 persent chance get failure result");
			return;
		}

		bc.setBcRef(StringUtil.number(24));
		bc.setBcCard(card.getCrdFake());
		bc.setBcTime(DateUtil.format(new Date(), DateUtil.DATE));
		bc.setBcMark("00");
		bc.setBcInfo("payment ok");
		bc.setBcCode(TransactionDict.TRANSACTION_SUCCESS);
		bc.setBcMessage(TransactionDict.MESSAGES.get(TransactionDict.TRANSACTION_SUCCESS));
		bc.setBcState("1");
		return;
	}

}